<!--
 * @Author: your name
 * @Date: 2021-02-15 20:59:04
 * @LastEditTime: 2021-03-02 13:36:34
 * @LastEditors: Please set LastEditors
 * @Description: 没有三级菜单
 * @FilePath: \jianfa-admin\src\page\project-code\code-list\index.vue
-->
<template>
  <Container class="code-list">
    <!-- <div id="qrcode"></div>  -->
    <Breadcrumb :navList="$route.meta.nav"></Breadcrumb>
    <avue-crud
      :data="data"
      :option="option"
      :page.sync="page_config"
      @size-change="sizeChange"
      @current-change="currentChange"
      :table-loading="loading"
    >
      <template slot="header">
        <el-form inline>
          <el-form-item>
            <el-button type="primary" @click="AddFiles">添加文件</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="file_img" slot-scope="scope">
        <el-image
          style="width: 100px; height: 100px"
          :src="`${IMGPATH}/${scope.row.file_path}`"
          :preview-src-list="[`${IMGPATH}/${scope.row.file_path}`]"
        >
        </el-image>
      </template>
      <template slot-scope="{ type, size, row }" slot="menu">
        <!--  <el-button
          icon="el-icon-edit"
          :size="size"
          :type="type"
          @click="toEdit(row.id)"
          >编辑</el-button
        > -->
        <del-button :size="size" :type="type" @click="delPro(row.id)">
          删除</del-button
        >
      </template>
    </avue-crud>
    <AddFiles
      :visible.sync="AddFilesVisible"
      :currentMenu="currentMenu"
      @getData="getData(api_params)"
    />
  </Container>
</template>
<script>
import mixins_page from "@/assets/mixins/paging";
import AddMenu from "./components/addMenu";
import AddFiles from "./components/addFiles";
export default {
  mixins: [mixins_page],
  components: {
    AddMenu,
    AddFiles,
  },
  data() {
    return {
      AddFilesVisible: false, //添加文件弹窗
      loading: true,
      data: [],
      menu: [], //三级菜单
      currentMenu: {
       type:this.$route.meta.type
      }, //当前选中的menu对象
      option: {
        searchShow: false,
        searchSize: "mini",
        // page: true,
        index: true,
        indexLabel: "序号",
        editBtn: false,
        delBtn: false,
        refreshBtn: false,
        addBtn: false,
        cancelBtn: false,
        align: "center",
        menuAlign: "center",
        column: [
          {
            label: "内容",
            prop: "file_img",
            slot: true,
            width: "200px",
          },
          {
            label: "文件路径",
            prop: "file_path",
          },
          {
            label: "创建日期",
            prop: "create_time",
            width: "200px",
          },
        ],
      },
    };
  },
  created() {
 
  },
  methods: {
    //添加文件弹窗
    AddFiles() {
     this.AddFilesVisible = true;
    },
    // 删除菜单文件
    async delPro(id) {
      const { code, msg } = await this.$api.menu.delMenuFiles({
        id,
        table_name: this.$route.meta.table_name + "_files",
      });
      if (!code) {
        this.$message.success(msg);
        this.getData(this.api_params);
      }
    },
    //获取工程项目列表
    async getData() {
      this.loading = true;
      const {
        code,
        data: { results, total },
      } = await this.$api.menu.getMenuFiles({
        table_name: this.$route.meta.table_name + "_files",
        sid:this.$route.meta.sid,
        ...this.api_params,
      });
      if (!code) {
        this.data = results;
        this.page_config.total = total;
        this.loading = false;
      }
    },
  },
};
</script>
<style lang='scss' scoped>
</style>